package com.hnhy.hnhyscms_ws.controller;

import com.hnhy.hnhyscms_ws.entity.Cpstorage;
import com.hnhy.hnhyscms_ws.entity.OrDetails;
import com.hnhy.hnhyscms_ws.service.ICpstorageService;
import com.hnhy.hnhyscms_ws.service.IOrDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/orderdetails")
public class OrDetailsController {
    @Autowired
    private IOrDetailsService iOrDetailsService;
    @Autowired
    private ICpstorageService iCpstorageService;
    @RequestMapping(value = "/getByOrderNo",method = RequestMethod.POST)
    public List<OrDetails> getByOrderNo(@RequestParam String orderNo){ return  iOrDetailsService.getByOrderNo(orderNo); }
    @RequestMapping(value = "/getAllOrderDetails",method = RequestMethod.GET)
    public List<OrDetails> getAllOrderDetails(){ return  iOrDetailsService.getAllOrderDetails(); }
    @RequestMapping(value = "/countByCustomerNo",method = RequestMethod.POST)
    public List<OrDetails> countByCustomerNo(String customerNo){ return  iOrDetailsService.countByCustomerNo(customerNo); }
    @RequestMapping(value = "/addOrderDetails",method = RequestMethod.POST)
    public void addOrderDetails(
            @RequestParam String orderNo,
            @RequestParam String productNo,
            @RequestParam Float orderAmount,
            @RequestParam Float amount,
            @RequestParam Float price)
    {
        OrDetails orderdetail=new OrDetails();
        Cpstorage cpstorage=iCpstorageService.getByProductNo(productNo);
        orderdetail.setProductNo(productNo);
        orderdetail.setProductName(cpstorage.getProductName());
        orderdetail.setOrderAmount(orderAmount);
        orderdetail.setAmount(amount);
        orderdetail.setBand(cpstorage.getBand());
        orderdetail.setUnit(cpstorage.getUnit());
        orderdetail.setPrice(price);
        orderdetail.setTotal(amount*price);
        orderdetail.setFinalTotal(orderAmount*price);
        orderdetail.setOrderNo(orderNo);
        orderdetail.setSpec(cpstorage.getSpec());
        iOrDetailsService.addOrDetails(orderdetail);
        return  ;
    }
}
